package com.young.study.Properties;

import java.io.*;
import java.util.Properties;

public class Demo01 {

    public static void main(String[] args) throws IOException {
//        testPropertiesStore();
        testLoadProperties();
    }

    /**
     * 测试properties的存储
     */
    static void testPropertiesStore() throws IOException {
        Properties pro = new Properties();
        pro.setProperty("userName","yanggaung");
        FileWriter writer=null;
        try {
            //设置properties的路径
            //1.将路径设置为绝对路径
            //writer = new FileWriter("E:/1.properties");
            //2.将项目设置为相对路径（相对于项目的根目录）
            writer = new FileWriter(new File("/1.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        pro.store(writer,"test");
    }

    static void  testLoadProperties() throws IOException{
        Properties pro = new Properties();
        //从相对路径上加载properties文件
        pro.load(new FileReader(new File("/1.properties")));
        String userName= pro.getProperty("userName");
        System.out.println(userName);
    }
}
